home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 18.8 KB | 433 lines |
- package symantec.itools.db.awt;
-
- import symjava.sql.*;
- import symantec.itools.db.pro.*;
- import symantec.itools.awt.*;
- import java.awt.*;
- public class DBTstamp extends symantec.itools.awt.Tstamp implements ProjLink
- {
-
- private ProjBinder m_ProjBinder;
- private String m_ScreenData;
- private String m_BinderData;
- private int m_treatBlankAs;
- private boolean m_BinderDetermines = false;
- public final static int Default = 0;
- public final static int Null = 1;
- public final static int Blank = 2;
- private String DBDF="Y*-MM-DD-hh-mm-ss-n9";
- private String DBEF="YMDhmsn";
- private String TYPE="Timestamp";
- public static String Time="Time";
- public static String Timestamp="Timestamp";
- public static String Date="Date";
- public DBTstamp()
- {
- super();
-
- m_BinderData = new String();
- m_ScreenData = new String();
-
- }
- public void setDBDF(String form)
- {
- DBDF=form;
- }
- public String getDBDF()
- {
- return(DBDF);
- }
- public void setDBEF(String form)
- {
- DBEF=form;
- }
- public String getDBEF()
- {
- return(DBEF);
- }
- public String getType()
- {
- return(TYPE);
- }
- public void setType(String type)
- {
-
- TYPE=type;
- if(type.equals("Date")){
-
- this.setDisplayFormat("D* M* D%TH, Y*");
- this.setEntryFormat("MDY");
- setDBDF("Y*-MM-DD");
- setDBEF("YMD");
- }
- if(type.equals("Timestamp")){
- this.setDisplayFormat("D* M* D%TH, Y* H%:m%:s%,n3 AM");
- this.setEntryFormat("MDYhmsn");
- setDBDF("Y*-MM-DD-hh-mm-ss-n9");
- setDBEF("YMDhmsn");
- }
- if(type.equals("Time")){
- this.setDisplayFormat("H%:m%:s% AM");
- this.setEntryFormat("hms");
- setDBDF("hh-mm-ss");
- setDBEF("hmsn");
- }
- }
- public void init(ProjBinder binder)
- {
- m_ProjBinder = binder;
- setEditable(m_ProjBinder);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setBinding //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public void setBinding(RelationView relView, String projection) throws SQLException
- {
- try {
- int projectionNumber = relView.findProjByName(projection);
- relView.bindProj(projectionNumber, this);
- }
- catch (SQLException Ex)
- {
- super.raiseException(
- "SQLException from setBinding: "
- + Ex.getMessage());
- }
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setDynamicUpdate //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public void setDynamicUpdate(boolean update)
- {
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setTreatBlankAs //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
-
- public void setTreatBlankAs(int treatAs)
- {
- switch(treatAs)
- {
- case Default:
- {
- m_treatBlankAs = RelationView.SETBLANKTODEFAULT;
- }
- case Null:
- {
- m_treatBlankAs = RelationView.SETBLANKTONULL;
- }
- case Blank:
- {
- m_treatBlankAs = RelationView.SETBLANKTOEMPTY;
- }
- }
- }
- //*************************************************************************//
- // //
- // FUNCTION: notifyDataChange //
- // //
- // PURPOSE: //
- // Implement the ProjLink interface function, notifyDataChange(). //
- // This function is called when the projection's data changes at //
- // the database. //
- // //
- // PARAMETERS: //
- // @param binder The ProjBinder binder object which this component can use//
- // to get or change data at the database server. //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- // Step 1: set m_ProjBinder equal to binder object //
- // Step 2: synchronize m_BinderData with binder object //
- // Step 3: synchronize m_ScreenData with current screen //
- // Step 4: if the two are different then //
- // - set m_ScreenData equal to m_BinderData to avoid recursion //
- // - call setText to update screen //
- // Step 5: enable or disable editing based on binder //
- // //
- //*************************************************************************//
-
- public void notifyDataChange(ProjBinder binder)
- {
- m_BinderData = "";
- if (binder == null)
- {
- return;
- }
- m_ProjBinder = binder;
-
- try
- {
- if (binder.getRelationView().getCurrentRecordState()
- != Record.RECSTATE_INVALID)
- {
- if (binder.isReadable() && !binder.isNull())
- {
- if(TYPE.equals("Date"))
- m_BinderData = binder.getDate().toString();
- if(TYPE.equals("Time"))
- m_BinderData = binder.getTime().toString();
- if(TYPE.equals("Timestamp"))
- m_BinderData = binder.getTimestamp().toString();
- }
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from TextField.notifyDataChange.getString: "
- + Ex.getMessage());
- }
- if (m_BinderData == null)
- {
- m_BinderData = new String();
-
- }
-
- m_ScreenData = getText();
-
- if (!m_BinderData.equals(m_ScreenData))
- {
- m_ScreenData = m_BinderData;
- if(m_BinderData.length()==0){
- setText("");
- }
- else{
- readDate(m_ScreenData,DBEF);
- setText(exTstamp(getDisplayFormat()));
- }
- }
-
- if (m_BinderDetermines)
- {
- setEditable(m_ProjBinder);
- }
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: notifyInputChange //
- // //
- // PURPOSE: Handle any event that causes us to send data to binder object //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- // //
- // Step 1: synchronize m_ScreenData with current screen //
- // Step 2: if m_ScreenData differs from m_BinderData then... //
- // - set m_BinderData equal to m_ScreenData to avoid recursion //
- // - call m_Binder.setString to update binder //
- // //
- //*************************************************************************//
-
- boolean notifyInputChanged(String input)
- {
- if (!m_ScreenData.equals(input))
- {
- m_ScreenData = input;
- }
- try{
- Tstamp TS= new Tstamp(m_BinderData,DBEF);
-
- if (!TS.getTstamp(getDisplayFormat()).equals(m_ScreenData)
- && (m_ProjBinder.getRelationView().getCurrentRecordState() != Record.RECSTATE_INVALID)
- && (m_ProjBinder.getRelationView().getCurrentRecordState() != Record.RECSTATE_DELETED)
- && (m_ProjBinder.getRelationView().getCurrentRecordState() != Record.RECSTATE_DB_DELETED)
- )
- {
-
-
- m_BinderData = m_ScreenData;
- readDate(m_BinderData,getDisplayFormat());
-
- try
- {
-
- if(m_ScreenData.trim().length()!=0){
- if (TYPE.equals("Date"))
- m_ProjBinder.setDate(new symjava.sql.Date(year-1900,month,day));
- if (TYPE.equals("Time"))
- m_ProjBinder.setTime(new symjava.sql.Time(hour,minute,second));
- if (TYPE.equals("Timestamp"))
- m_ProjBinder.setTimestamp(new symjava.sql.Timestamp(year-1900,month,day,hour,minute,second,nanosec));
- }
- if(m_ScreenData.trim().length()==0&&!m_ProjBinder.isNull()){
- if (TYPE.equals("Date"))
- m_ProjBinder.setNull(Types.DATE);
- if (TYPE.equals("Time"))
- m_ProjBinder.setNull(Types.TIME);
- if (TYPE.equals("Timestamp"))
- m_ProjBinder.setNull(Types.TIMESTAMP);
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from TextField.notifyInputChange: "
- + Ex.getMessage());
- return false;
- }
- }
- }catch (SQLException Ex)
- {
- raiseException(
- "SQLException from TextField.notifyInputChange: "
- + Ex.getMessage());
- return false;
- }
- return true;
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: notifySetData //
- // //
- // PURPOSE: Send data to binder //
- // //
- // PARAMETERS: //
- // @param binder The ProjBinder binder object which this component can use//
- // to change data at the database server. //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- // //
- //*************************************************************************//
-
- public boolean notifySetData(ProjBinder binder) throws SQLException
- {
- return ( notifyInputChanged(getText()) );
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setEditable //
- // //
- // PURPOSE: Enable or disable input //
- // //
- // PARAMETERS: //
- // @param binder The ProjBinder binder object which this component can use//
- // to change data at the database server. //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- void setEditable(ProjBinder binder)
- {
- //Disable input if binder is not writeable
- boolean isWritable = false;
-
- try
- {
- if (binder != null)
- {
- RelationView rv = binder.getRelationView();
- if (rv != null && (rv.getCurrentRecordState()
- != Record.RECSTATE_INVALID))
- {
- isWritable = binder.isWritable();
- }
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from setEditable: "
- + Ex.getMessage());
- }
- super.setEditable(isWritable);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setEditable //
- // //
- // PURPOSE: Set editable attribute //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public void setEditable(boolean value)
- {
- m_BinderDetermines = value;
- super.setEditable(value);
- }
-
- public void setDisplayFormat(String dispFmt)
- {
- super.setDisplayFormat(dispFmt);
- notifyDataChange(m_ProjBinder);
- }
- public boolean handleEvent(Event event) {
- if(event.id==Event.ACTION_EVENT||event.id==Event.LOST_FOCUS)
- {
- if(event.id==Event.ACTION_EVENT&&getText().trim().length()<3)
- {
- if(m_BinderData.length()==0)
- setTstamp(new java.util.Date());
- printTstamp();
- notifyInputChanged(getText());
- }
- if(getText().trim().length()>=3)
- {
- setTstamp(getText(),getEntryFormat());
- printTstamp();
- notifyInputChanged(getText());
- }
- }
- return(false);
-
- }
- }
-